public class ReverseWordsInAStringIII {
    /**
     * 给定一个字符串 s ，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。
     * @param s
     * @return
     */
    public static String reverseWords(String s) {
        String[] strings = s.split(" ");
        String ans = "";
        for (String str:strings){
             char[] chars = str.toCharArray();
             reverseString(chars);
             str= String.valueOf(chars);
        }
        return ans;
    }

    public static void reverseString(char[] s) {
        if (s.length==1)
            return;
        int len = s.length/2;
        for (int i=0;i<len;i++){
            char temp = s[i];
            s[i] = s[s.length-1-i];
            s[s.length-1-i] = temp;
        }
    }

    public static void main(String[] args) {
        System.out.println(reverseWords("Let's take LeetCode contest"));

    }
}
